/**
 *  Copyright (C) 2008 Richard Hall
 *
 *  This program is free software; you can redistribute it and/or modify it under the terms of the 
 *  GNU General Public License as published by the Free Software Foundation; either version 3 of the 
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
 *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *  See the GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along with this program; if not, 
 *  see <http://www.gnu.org/licenses>.
 *
 *  Additional permission under GNU GPL version 3 section 7
 *
 *  If you modify this Program, or any covered work, by linking or combining it with [name of library] 
 *  (or a modified version of that library), containing parts covered by the terms of 
 *  [name of library's license], the licensors of this Program grant you additional permission to 
 *  convey the resulting work. {Corresponding Source for a non-source form of such a combination shall 
 *  include the source code for the parts of [name of library] used as well as that of the 
 *  covered work.}
 *
 * 
 */

package com.gpsmedia.gui.frames;

import com.google.gdata.util.AuthenticationException;
import com.gpsmedia.control.GPS2Google;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.event.*;
import java.io.*;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.Date;
import java.awt.*;
import java.net.URL;
import com.gpsmedia.gui.*;
import java.util.ArrayList;
import com.gpsmedia.uploadutils.BlipTvTools;
import com.gpsmedia.uploadutils.PicasaTools;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;

/**
 * This is the main class for the application. It has been used a as graphical wrapper for the 
 * GPS2Google class. It is not required if the API is being used. 
 *
 * @author  Richard Hall
 */
public class MainFrame extends javax.swing.JFrame {

    //keeps track of the status of the "go" button

    private int buttonType = 0;
    private GPS2Google gps2ginstance = new GPS2Google();
    private ArrayList logoList = new ArrayList();
    private int previousPane = 0;
    /** Creates new form MainFrame */

    public MainFrame() {
        ClassLoader loader = getClass().getClassLoader();
        URL fileLocation = loader.getResource("com/gpsmedia/images/earth_small.jpg");
        Image logo = Toolkit.getDefaultToolkit().getImage(fileLocation);
        logoList.add(logo);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        lblInputFile = new javax.swing.JLabel();
        txtInputFile = new javax.swing.JTextField();
        btnInputFile = new javax.swing.JButton();
        lblOutputFile = new javax.swing.JLabel();
        txtOutputFile = new javax.swing.JTextField();
        btnOutputFile = new javax.swing.JButton();
        chkPicturePane = new javax.swing.JCheckBox();
        chkAudioPane = new javax.swing.JCheckBox();
        btnGo = new javax.swing.JButton();
        lblTimeZone = new javax.swing.JLabel();
        tcbTimeZone = new com.gpsmedia.gui.controls.TimeZoneComboBox();
        sliderDOP = new javax.swing.JSlider();
        lblDOP = new javax.swing.JLabel();
        lblDOPValue = new javax.swing.JLabel();
        chkIncAlt = new javax.swing.JCheckBox();
        txtKMLTitle = new javax.swing.JTextField();
        lblKmlTitle = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        lblHelpFiles = new javax.swing.JEditorPane();
        jPanel2 = new javax.swing.JPanel();
        lblPictureFolder = new javax.swing.JLabel();
        txtPictureFolder = new javax.swing.JTextField();
        btnPictureFolder = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lblPictureUpload = new javax.swing.JEditorPane();
        txtGoogleUserName = new javax.swing.JTextField();
        lblGoogleUsername = new javax.swing.JLabel();
        lblGooglePassword = new javax.swing.JLabel();
        pswdGoogle = new javax.swing.JPasswordField();
        lblFirstPicTime = new javax.swing.JLabel();
        jspinTimePic = new javax.swing.JSpinner();
        chkPictureUpload = new javax.swing.JCheckBox();
        jPanel3 = new javax.swing.JPanel();
        lblAudioFolder = new javax.swing.JLabel();
        txtAudioFolder = new javax.swing.JTextField();
        btnAudioFolder = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lblAudioUpload = new javax.swing.JEditorPane();
        lblBlipPassword = new javax.swing.JLabel();
        lblBlipUsername = new javax.swing.JLabel();
        txtBliptvUserName = new javax.swing.JTextField();
        pswdBliptv = new javax.swing.JPasswordField();
        lblFirstAudioTime = new javax.swing.JLabel();
        jspinTimeAudio = new javax.swing.JSpinner();
        chkAudioUpload = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GPS2GE");
        setIconImages(logoList);
        setResizable(false);

        lblInputFile.setText("Input File:");

        txtInputFile.setEditable(false);

        btnInputFile.setText("Select File");
        btnInputFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInputFileActionPerformed(evt);
            }
        });

        lblOutputFile.setText("Output File:");

        txtOutputFile.setEditable(false);

        btnOutputFile.setText("Select File");
        btnOutputFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOutputFileActionPerformed(evt);
            }
        });

        chkPicturePane.setText("Tag Pictures");
        chkPicturePane.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkPicturePaneActionPerformed(evt);
            }
        });

        chkAudioPane.setText("Tag Audio");
        chkAudioPane.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkAudioPaneActionPerformed(evt);
            }
        });

        btnGo.setText("Go");
        btnGo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGoActionPerformed(evt);
            }
        });

        lblTimeZone.setText("Time Zone:");

        sliderDOP.setValue(0);
        sliderDOP.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sliderDOPStateChanged(evt);
            }
        });

        lblDOP.setText("Dilution of Precision (2D):");

        lblDOPValue.setText("0");

        chkIncAlt.setText("Include Altitude");
        chkIncAlt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkIncAltActionPerformed(evt);
            }
        });

        lblKmlTitle.setText("KML Title:");

        lblHelpFiles.setBackground(java.awt.SystemColor.menu);
        lblHelpFiles.setBorder(null);
        lblHelpFiles.setEditable(false);
        lblHelpFiles.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jScrollPane3.setViewportView(lblHelpFiles);
        lblHelpFiles.addHyperlinkListener(linkListener);

        lblHelpFiles.setContentType("text/html");
        String fileLocation = "";
        try{
            fileLocation = new File(".").getCanonicalPath();
        }catch(IOException e){
            //will never occur
        }

        fileLocation = fileLocation.replaceAll(" ", "%20");

        lblHelpFiles.setText("<a  href=\"file:///"+fileLocation+"/help/index.html\">Help</a><br/>");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(chkPicturePane)
                        .addGap(18, 18, 18)
                        .addComponent(chkAudioPane, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chkIncAlt))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblDOP, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(sliderDOP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblDOPValue, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnGo, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblTimeZone)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tcbTimeZone, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(lblInputFile, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblOutputFile, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(lblKmlTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtKMLTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtOutputFile, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtInputFile, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnOutputFile)
                            .addComponent(btnInputFile)))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblInputFile)
                            .addComponent(txtInputFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtOutputFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblOutputFile))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtKMLTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblKmlTitle))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chkPicturePane)
                            .addComponent(chkAudioPane)
                            .addComponent(chkIncAlt))
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblTimeZone)
                            .addComponent(tcbTimeZone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnInputFile)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnOutputFile)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sliderDOP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDOPValue)
                    .addComponent(lblDOP)
                    .addComponent(btnGo))
                .addGap(7, 7, 7)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("General", jPanel1);

        lblPictureFolder.setText("Picture Folder:");

        txtPictureFolder.setEditable(false);
        txtPictureFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPictureFolderActionPerformed(evt);
            }
        });

        btnPictureFolder.setText("Select Folder");
        btnPictureFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPictureFolderActionPerformed(evt);
            }
        });

        lblPictureUpload.setBackground(java.awt.SystemColor.menu);
        lblPictureUpload.setBorder(null);
        lblPictureUpload.setEditable(false);
        lblPictureUpload.addHyperlinkListener(linkListener);

        lblPictureUpload.setContentType("text/html");
        lblPictureUpload.setText("Please enter your username and password for <a  href=\"http://picasaweb.google.com\"> Picasa Web Albums</a><br/>Click on the link to sign up for an account!");
        lblPictureUpload.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jScrollPane1.setViewportView(lblPictureUpload);

        txtGoogleUserName.setEditable(false);
        txtGoogleUserName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtGoogleUserNameActionPerformed(evt);
            }
        });

        lblGoogleUsername.setText("Google username:");

        lblGooglePassword.setText("Google password:");

        pswdGoogle.setEditable(false);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 420, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblGooglePassword, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblGoogleUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtGoogleUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(pswdGoogle, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(86, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(lblGoogleUsername)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblGooglePassword))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(txtGoogleUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pswdGoogle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lblFirstPicTime.setText("<html><body>Time first picture was <br> taken (according to the GPS device):</body></html>");
        lblFirstPicTime.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);

        jspinTimePic.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(), new java.util.Date(-3600000L), null, java.util.Calendar.SECOND));
        jspinTimePic.setEditor(new javax.swing.JSpinner.DateEditor(jspinTimePic,"dd/MM/yyyy HH:mm:ss"));

        chkPictureUpload.setText("Upload Pictures");
        chkPictureUpload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkPictureUploadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(chkPictureUpload)
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(lblFirstPicTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(jspinTimePic, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(49, 49, 49))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(lblPictureFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtPictureFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnPictureFolder)))
                        .addGap(64, 64, 64))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnPictureFolder)
                    .addComponent(txtPictureFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPictureFolder))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jspinTimePic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFirstPicTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(chkPictureUpload)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );

        jTabbedPane1.addTab("Pictures", jPanel2);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, chkAudioPane, org.jdesktop.beansbinding.ELProperty.create("${selected}"), jPanel3, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        lblAudioFolder.setText("Audio Folder:");

        txtAudioFolder.setEditable(false);

        btnAudioFolder.setText("Select Folder");
        btnAudioFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAudioFolderActionPerformed(evt);
            }
        });

        lblAudioUpload.setBackground(java.awt.SystemColor.menu);
        lblAudioUpload.setEditable(false);
        lblAudioUpload.addHyperlinkListener(linkListener);

        lblAudioUpload.setContentType("text/html");
        lblAudioUpload.setText("Please enter your username and password for <a  href=\"http://blip.tv\">Blip.tv</a><br/>Click on the link to sign up for an account!");
        jScrollPane2.setViewportView(lblAudioUpload);

        lblBlipPassword.setText("Blip.tv password:");

        lblBlipUsername.setText("Blip.tv username:");

        txtBliptvUserName.setEditable(false);
        txtBliptvUserName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBliptvUserNameActionPerformed(evt);
            }
        });

        pswdBliptv.setEditable(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(lblBlipUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBliptvUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(lblBlipPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pswdBliptv, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 420, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(86, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBlipUsername)
                    .addComponent(txtBliptvUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBlipPassword)
                    .addComponent(pswdBliptv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        lblFirstAudioTime.setText("<html><body>Time first recording was <br> started (according to the GPS device):</body></html>");
        lblFirstAudioTime.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);

        jspinTimeAudio.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(), new java.util.Date(-3600000L), null, java.util.Calendar.SECOND));
        jspinTimeAudio.setEditor(new javax.swing.JSpinner.DateEditor(jspinTimeAudio,"dd/MM/yyyy HH:mm:ss"));

        chkAudioUpload.setText("Upload Audio");
        chkAudioUpload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkAudioUploadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(chkAudioUpload)
                        .addContainerGap())
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(lblAudioFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtAudioFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnAudioFolder))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(lblFirstAudioTime, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                                .addGap(26, 26, 26)
                                .addComponent(jspinTimeAudio, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(49, 49, 49)))
                        .addGap(78, 78, 78))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAudioFolder)
                    .addComponent(lblAudioFolder)
                    .addComponent(txtAudioFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblFirstAudioTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jspinTimeAudio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addComponent(chkAudioUpload)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Audio", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 541, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jTabbedPane1.setEnabledAt(1,chkPicturePane.isSelected());
        jTabbedPane1.setEnabledAt(2,chkAudioPane.isSelected());

        jTabbedPane1.addChangeListener(new ChangeListener(){
            public void stateChanged(ChangeEvent evt) {
                JTabbedPane tempPane = (JTabbedPane)evt.getSource();
                int currentPane = tempPane.getSelectedIndex();

                if(previousPane==1){
                    if(chkPictureUpload.isSelected()){
                        try{
                            PicasaTools pt = new PicasaTools(txtGoogleUserName.getText(), String.copyValueOf(pswdGoogle.getPassword()).toString());
                        } catch (AuthenticationException ex) {
                            JOptionPane.showMessageDialog(null, "Incorrect Google Username/Password","Incorrect Google Username/Password", JOptionPane.ERROR_MESSAGE);
                            previousPane = 0;
                            jTabbedPane1.setSelectedIndex(1);
                            currentPane = 1;
                        }

                    }
                }else if(previousPane==2){
                    if(chkAudioUpload.isSelected()){
                        try{
                            BlipTvTools bt = new BlipTvTools(txtBliptvUserName.getText(), String.copyValueOf(pswdBliptv.getPassword()).toString());
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(null, "Incorrect Blip Username/Password","Incorrect Blip Username/Password", JOptionPane.ERROR_MESSAGE);
                            previousPane = 0;
                            jTabbedPane1.setSelectedIndex(2);
                            currentPane = 2;
                        }
                    }
                }

                if(currentPane==0){
                    previousPane = 0;
                }else if(currentPane==1){
                    previousPane = 1;
                }else{
                    previousPane = 2;
                }

            }
        });

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
	 * Button to open a File Dialog Box to select the GPS Log file.
	 * 
	 * @param evt
	 */
    private void btnInputFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInputFileActionPerformed
        // TODO add your handling code here:
        JFileChooser inputFileChooser = new JFileChooser() {

                    public void approveSelection() {
                        File f = getSelectedFile();
                        boolean fileOk = false;
                        if (f.isDirectory() != true) {
                            if (f.getName().endsWith(".log") || f.getName().endsWith(".LOG")) {
                                fileOk = true;
                            }
                            if (fileOk == true) {

                                super.approveSelection();
                            } else {
                                setSelectedFile(null);
                            }
                        } else {
                            setSelectedFile(null);
                        }
                    }

                    @Override
            public void cancelSelection() {
                        setSelectedFile(null);
                        super.cancelSelection();
                    }
                };


        inputFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

        FileFilter ff = new FileFilter() {

                    @Override
	public boolean accept(File file) {
                        boolean accept;

                        if (file.isDirectory() == true || file.getName().endsWith(".log") ||
                                file.getName().endsWith(".LOG")) {
                            accept = true;
                        } else {

                            accept = false;
                        }
                        return accept;
                    }

                    @Override
        public String getDescription() {
                        return "All .log files, *.log";
                    }
                };
        inputFileChooser.setFileFilter(ff);
        inputFileChooser.showOpenDialog(jPanel1);
        if (inputFileChooser.getSelectedFile() != null) {
            txtInputFile.setText(inputFileChooser.getSelectedFile().getAbsolutePath());
        }
    }//GEN-LAST:event_btnInputFileActionPerformed

    /**
	 * Button to open a File Dialog Box to select an output file.
	 * 
	 * @param evt
	 */
    private void btnOutputFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOutputFileActionPerformed

        // TODO add your handling code here:
        // TODO add your handling code here:
        JFileChooser outputFileChooser = new JFileChooser() {

                    public void approveSelection() {
                        File f = getSelectedFile();
                        boolean fileOk = false;
                        if (f.isDirectory() != true) {
                            if (f.getName().endsWith(".kml") || f.getName().endsWith(".KML")) {
                                fileOk = true;
                            } else {
                                f = new File(f.getAbsoluteFile() + ".kml");
                                setSelectedFile(f);
                            }
                            super.approveSelection();
                        }

                    }

                    @Override
            public void cancelSelection() {
                        setSelectedFile(null);
                        super.cancelSelection();
                    }
                };

        outputFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

        FileFilter ff = new FileFilter() {

                    @Override
	public boolean accept(File file) {
                        boolean accept;

                        if (file.isDirectory() == true || file.getName().endsWith(".kml") ||
                                file.getName().endsWith(".KML")) {
                            accept = true;
                        } else {

                            accept = false;
                        }
                        return accept;
                    }

                    @Override
        public String getDescription() {
                        return "All .kml files, *.kml";
                    }
                };
        outputFileChooser.setFileFilter(ff);
        outputFileChooser.showSaveDialog(jPanel1);
        if (outputFileChooser.getSelectedFile() != null) {
            txtOutputFile.setText(outputFileChooser.getSelectedFile().getAbsolutePath());
        }
    
           
    }//GEN-LAST:event_btnOutputFileActionPerformed

    /**
	 * Indicates that an action has occurred with the picture check box
	 * 
	 * @param evt
	 */
    private void chkPicturePaneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPicturePaneActionPerformed
        // TODO add your handling code here:
        if (chkPicturePane.isSelected() == true) {
            jTabbedPane1.setEnabledAt(1, true);

        } else {
            jTabbedPane1.setEnabledAt(1, false);
        }
    }//GEN-LAST:event_chkPicturePaneActionPerformed

    /**
	 * Indicates that an action has occurred with the audio check box
	 * 
	 * @param evt
	 */
    private void chkAudioPaneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAudioPaneActionPerformed
        // TODO add your handling code here:
        if (chkAudioPane.isSelected() == true) {
            jTabbedPane1.setEnabledAt(2, true);

        } else {
            jTabbedPane1.setEnabledAt(2, false);
        }
    }//GEN-LAST:event_chkAudioPaneActionPerformed

    /**
	 * Button used to start the process.
	 * 
	 * @param evt
	 */
    private void btnGoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGoActionPerformed
        // TODO add your handling code here:
        if (txtInputFile.getText().compareToIgnoreCase("") != 0 && txtOutputFile.getText().compareToIgnoreCase("") != 0) {
            if ((chkAudioPane.isSelected() && txtAudioFolder.getText().compareToIgnoreCase("") != 0) ||
                    chkAudioPane.isSelected() == false) {

                if ((chkPicturePane.isSelected() && txtPictureFolder.getText().compareToIgnoreCase("") != 0) ||
                        chkPicturePane.isSelected() == false) {

                    if ((chkAudioUpload.isSelected() && txtBliptvUserName.getText().compareToIgnoreCase("") != 0 &&
                            String.copyValueOf(pswdBliptv.getPassword()).compareToIgnoreCase("") != 0) ||
                            chkAudioUpload.isSelected() == false) {


                        if ((chkPictureUpload.isSelected() && txtGoogleUserName.getText().compareToIgnoreCase("") != 0 && String.copyValueOf(pswdGoogle.getPassword()).toString().compareToIgnoreCase("") != 0) ||
                                chkPictureUpload.isSelected() == false) {



                            if (buttonType == 0) {
                                try {


                                    Calendar picTime = Calendar.getInstance();

                                    if (chkPicturePane.isSelected()) {
                                        picTime.clear();
                                        picTime.setTime((Date) jspinTimePic.getValue());
                                    }

                                    Calendar audioTime = Calendar.getInstance();

                                    if (chkAudioPane.isSelected()) {
                                        audioTime.clear();
                                        audioTime.setTime((Date) jspinTimeAudio.getValue());
                                    }

                                    gps2ginstance.setparams(txtInputFile.getText(), txtOutputFile.getText(), txtPictureFolder.getText(), txtAudioFolder.getText(), picTime, audioTime, (TimeZone) tcbTimeZone.getSelectedItem(), txtGoogleUserName.getText(), pswdGoogle.getPassword(), txtBliptvUserName.getText(), pswdBliptv.getPassword(), Double.parseDouble(lblDOPValue.getText()), chkIncAlt.isSelected(), txtKMLTitle.getText());
                                    gps2ginstance.readdata();
                                    //                  gps2ginstance.findtime("08:33:20");


                                    if (chkPicturePane.isSelected()) {
                                        buttonType++;
                                        this.btnGo.setText("Select Pics");
                                    } else if (chkPicturePane.isSelected() == false && chkAudioPane.isSelected()) {
                                        buttonType = buttonType + 2;
                                        this.btnGo.setText("Select Audio");
                                    } else {
                                        buttonType = buttonType + 3;
                                        this.btnGo.setText("Write KML");
                                    }
                                } catch (Exception ex) {
                                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                                }

                            } else if (buttonType == 1 && chkPicturePane.isSelected()) {
                                gps2ginstance.selectPics(true, this);

                                if (chkAudioPane.isSelected()) {
                                    buttonType++;
                                    this.btnGo.setText("Select Audio");
                                } else {
                                    buttonType = buttonType + 2;
                                    this.btnGo.setText("Write KML");
                                }

                            } else if (buttonType == 2) {
                                //select mp3s
                                gps2ginstance.selectAudio(true, this);
                                buttonType++;
                                this.btnGo.setText("Write KML");
                            } else if (buttonType == 3) {
                                try {
                                    //Write KML FILE
                                    gps2ginstance.sendData();
                                    gps2ginstance.writedata();
                                    buttonType = 0;
                                    this.btnGo.setText("Go");
                                } catch (Exception ex) {
                                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                                }

                            }
                        }
                    }
                }
            }
        }
    }//GEN-LAST:event_btnGoActionPerformed

    /**
	 * Button used to open a File Dialog Box to select the folder containing the
	 * pictures
	 * 
	 * @param evt
	 */
    private void btnPictureFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPictureFolderActionPerformed
        // TODO add your handling code here:
        JFileChooser pictureFolderChooser = new JFileChooser() {

                    public void approveSelection() {
                        File f = getSelectedFile();
                        boolean fileOk = false;
                        if (f.isDirectory()) {
                            String[] files = f.list();
                            for (int i = 0; i < files.length && fileOk == false; i++) {
                                if (files[i].endsWith(".jpg") || files[i].endsWith(".JPEG") || files[i].endsWith(".JPG") || files[i].endsWith("jpeg")) {
                                    fileOk = true;
                                }
                            }
                            if (fileOk == true) {

                                super.approveSelection();
                            } else {
                                setSelectedFile(null);
                            }
                        } else {
                            setSelectedFile(null);
                        }
                    }

                    @Override
            public void cancelSelection() {
                        setSelectedFile(null);
                        super.cancelSelection();
                    }
                };
        pictureFolderChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

        FileFilter ff = new FileFilter() {

                    @Override
	public boolean accept(File file) {
                        if (file.isDirectory() || file.getName().endsWith(".JPG") ||
                                file.getName().endsWith(".jpg") || file.getName().endsWith(".jpeg") ||
                                file.getName().endsWith(".JPEG")) {
                            return true;
                        } else {
                            return false;
                        }

                    }

                    @Override
        public String getDescription() {
                        return "All Files and Folders";
                    }
                };
        pictureFolderChooser.setFileFilter(ff);
        pictureFolderChooser.showOpenDialog(jPanel1);
        if (pictureFolderChooser.getSelectedFile() != null) {
            txtPictureFolder.setText(pictureFolderChooser.getSelectedFile().getAbsolutePath());
        }
}//GEN-LAST:event_btnPictureFolderActionPerformed

    /**
	 * Button used to open a File Dialog Box to select the folder containing the
	 * audio
	 * 
	 * @param evt
	 */
    private void btnAudioFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAudioFolderActionPerformed
        // TODO add your handling code here:
        JFileChooser audioFolderChooser = new JFileChooser() {

                    public void approveSelection() {
                        File f = getSelectedFile();
                        boolean fileOk = false;
                        if (f.isDirectory()) {
                            String[] files = f.list();
                            for (int i = 0; i < files.length && fileOk == false; i++) {
                                if (files[i].endsWith(".mp3") || files[i].endsWith(".MP3")) {
                                    fileOk = true;
                                }
                            }
                            if (fileOk == true) {

                                super.approveSelection();
                            } else {
                                setSelectedFile(null);
                            }
                        } else {
                            setSelectedFile(null);
                        }
                    }

                    @Override
            public void cancelSelection() {
                        setSelectedFile(null);
                        super.cancelSelection();
                    }
                };
        audioFolderChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);


        FileFilter ff = new FileFilter() {

                    @Override
	public boolean accept(File file) {

                        if (file.isDirectory() || file.getName().endsWith(".mp3") || file.getName().endsWith(".MP3")) {
                            return true;
                        } else {
                            return false;
                        }

                    }

                    @Override
        public String getDescription() {
                        return "All File and Folders";
                    }
                };
        audioFolderChooser.setFileFilter(ff);
        audioFolderChooser.showOpenDialog(jPanel1);
        if (audioFolderChooser.getSelectedFile() != null) {
            txtAudioFolder.setText(audioFolderChooser.getSelectedFile().getAbsolutePath());
        }

}//GEN-LAST:event_btnAudioFolderActionPerformed

    private void txtPictureFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPictureFolderActionPerformed
    // TODO add your handling code here:
    }//GEN-LAST:event_txtPictureFolderActionPerformed

    private void tcbTimeZoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tcbTimeZoneActionPerformed
    // TODO add your handling code here:
    }//GEN-LAST:event_tcbTimeZoneActionPerformed

    /**
	 * Indicates whether the picture upload check box has been activated
	 * 
	 * @param evt
	 */
    private void chkPictureUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPictureUploadActionPerformed
        // TODO add your handling code here:

        if (chkPictureUpload.isSelected() == true) {
            txtGoogleUserName.setEditable(true);
            pswdGoogle.setEditable(true);

        } else {
            txtGoogleUserName.setText("");
            txtGoogleUserName.setEditable(false);
            pswdGoogle.setText("");
            pswdGoogle.setEditable(false);

        }
}//GEN-LAST:event_chkPictureUploadActionPerformed

    private void txtGoogleUserNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtGoogleUserNameActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_txtGoogleUserNameActionPerformed

    /**
	 * Indicates whether the audio upload check box has been activated
	 * 
	 * @param evt
	 */
    private void chkAudioUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkAudioUploadActionPerformed
        // TODO add your handling code here:
        if (chkAudioUpload.isSelected() == true) {
            txtBliptvUserName.setEditable(true);
            pswdBliptv.setEditable(true);

        } else {
            txtBliptvUserName.setText("");
            txtBliptvUserName.setEditable(false);
            pswdBliptv.setText("");
            pswdBliptv.setEditable(false);

        }
}//GEN-LAST:event_chkAudioUploadActionPerformed

    private void txtBliptvUserNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBliptvUserNameActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_txtBliptvUserNameActionPerformed

    /**
	 * Indicates an event on the slider
	 * 
	 * @param evt
	 */
    private void sliderDOPStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderDOPStateChanged
        // TODO add your handling code here:
        double tempDOP = sliderDOP.getValue();
        lblDOPValue.setText(String.valueOf(tempDOP / 10));
        
    }//GEN-LAST:event_sliderDOPStateChanged

    /**
	 * Indicates that the include altitude check box has been activated
	 * 
	 * @param evt
	 */
    private void chkIncAltActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkIncAltActionPerformed
        // TODO add your handling code here:
        if (chkIncAlt.isSelected()) {
            lblDOP.setText("Dilution of Precision (3D):");
        } else {
            lblDOP.setText("Dilution of Precision (2D):");
        }
    }//GEN-LAST:event_chkIncAltActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {

                    public void run() {
                        new MainFrame().setVisible(true);
                    }
                });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAudioFolder;
    private javax.swing.JButton btnGo;
    private javax.swing.JButton btnInputFile;
    private javax.swing.JButton btnOutputFile;
    private javax.swing.JButton btnPictureFolder;
    private javax.swing.JCheckBox chkAudioPane;
    private javax.swing.JCheckBox chkAudioUpload;
    private javax.swing.JCheckBox chkIncAlt;
    private javax.swing.JCheckBox chkPicturePane;
    private javax.swing.JCheckBox chkPictureUpload;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JSpinner jspinTimeAudio;
    private javax.swing.JSpinner jspinTimePic;
    private javax.swing.JLabel lblAudioFolder;
    private javax.swing.JEditorPane lblAudioUpload;
    private javax.swing.JLabel lblBlipPassword;
    private javax.swing.JLabel lblBlipUsername;
    private javax.swing.JLabel lblDOP;
    private javax.swing.JLabel lblDOPValue;
    private javax.swing.JLabel lblFirstAudioTime;
    private javax.swing.JLabel lblFirstPicTime;
    private javax.swing.JLabel lblGooglePassword;
    private javax.swing.JLabel lblGoogleUsername;
    private javax.swing.JEditorPane lblHelpFiles;
    private javax.swing.JLabel lblInputFile;
    private javax.swing.JLabel lblKmlTitle;
    private javax.swing.JLabel lblOutputFile;
    private javax.swing.JLabel lblPictureFolder;
    private javax.swing.JEditorPane lblPictureUpload;
    private javax.swing.JLabel lblTimeZone;
    private javax.swing.JPasswordField pswdBliptv;
    private javax.swing.JPasswordField pswdGoogle;
    private javax.swing.JSlider sliderDOP;
    private com.gpsmedia.gui.controls.TimeZoneComboBox tcbTimeZone;
    private javax.swing.JTextField txtAudioFolder;
    private javax.swing.JTextField txtBliptvUserName;
    private javax.swing.JTextField txtGoogleUserName;
    private javax.swing.JTextField txtInputFile;
    private javax.swing.JTextField txtKMLTitle;
    private javax.swing.JTextField txtOutputFile;
    private javax.swing.JTextField txtPictureFolder;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private HyperlinkListener linkListener = new HyperlinkListener() {

                public void hyperlinkUpdate(HyperlinkEvent hle) {
                    if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
                        try {
                            Desktop.getDesktop().browse(new URL(hle.getDescription()).toURI());
                        } catch (IOException ex) {
                            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (URISyntaxException ex) {
                            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }

                    }
                }
            };
}
